import { Vector3 } from "../math/Vector3";
import { Object3D } from "../objects/Object3D";
import { post } from "../utils/Client";
import { Mapper } from "../utils/Map";
import { defineReactive } from "../utils/Observe";
/**摄像机 */
class Camera extends Object3D {
  armlength: number = 0;
  constructor(options) {
    super();
    Camera.prototype.isCamera = true;
    Mapper.map(this, options);

    defineReactive(this, "position", (value, key) => {
      this.putProperty(key, key);
    });
    defineReactive(this, "rotation", (value, key) => {
      this.putProperty(key, key);
    });
    defineReactive(this, "armlength", (value, key) => {
      this.putProperty(key, key);
    });
  }
  /**
   * 更新属性值
   * @param prop 属性
   * @param key 事件
   * @param expand 是否展开值
   * @param alias 属性别名
   */
  private putProperty(prop, key, expand?, alias?) {
    if (expand) {
      post("preview_player", {
        ...this[prop],
        guid: this.guid,
        key,
      });
    } else {
      post("preview_player", {
        [alias || prop]: this[prop],
        guid: this.guid,
        key,
      });
    }
  }

  /**
   * 定位
   * @param position 位置
   * @param rotation 旋转角度
   * @param armlength 摇臂长度
   */
  orientation(position: Vector3, rotation: Vector3, armlength: number) {
    this.position = position;
    this.rotation = rotation;
    this.armlength = armlength;
  } 

}

export {
  Camera
}
